package com.want.buss.interfaces.service.impl;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.want.buss.interfaces.dto.CustomerAreaStoreParam;
import com.want.buss.interfaces.mapper.CustomerAreaStoreMapper;
import com.want.buss.interfaces.po.CustomerAreaStore;
import com.want.buss.interfaces.po.CustomerAreaStoreData;
import com.want.buss.interfaces.service.CustomerAreaStoreService;
import com.want.buss.interfaces.utils.BussStringUtils;

//@Service junit 测试使用
@WebService
public class CustomerAreaStoreServiceImpl implements CustomerAreaStoreService {
	Logger logger = Logger.getLogger(CustomerAreaStoreServiceImpl.class);  
	@Autowired
	CustomerAreaStoreMapper customerAreaStoreMapper;
	
	@WebMethod
	@Override
	public CustomerAreaStoreData queryCustomerAreaStore(CustomerAreaStoreParam customerAreaStoreParam) {
		CustomerAreaStoreData data = new CustomerAreaStoreData(); 
		// 参数判断
		if(validateParam(customerAreaStoreParam)!=""){
			data.setSuccess(false);
			data.setMsg(validateParam(customerAreaStoreParam));
		}else{
			try {
				List<CustomerAreaStore> customerAreaStores=customerAreaStoreMapper.queryCustomerAreaStore(customerAreaStoreParam);
				logger.info("customerAreaStores size-"+customerAreaStores.size());
				data.setSuccess(true);
				data.setCustomerAreaStores(customerAreaStores);
			} catch (Exception e) {
				data.setSuccess(false);
				data.setMsg(e.getMessage());
			}
		}
		return data;
	}

	/**
	 * 验证接口接收参数是否合理
	 * @param   CustomerAreaStoreParam
	 * @return  List<String>
	 */
	private String validateParam(CustomerAreaStoreParam param) {
		String msg="";
		
		if(param!=null){
			if(BussStringUtils.isEmpty(param.getCustomerId())){
				msg+="客户编码不能为空;\n";
			}
			if(param.getChannelIds()==null ||param.getChannelIds().length==0){
				msg+="旺旺渠道不能为空;\n";
			}
			if(BussStringUtils.isEmpty(param.getStoreId())
					&&BussStringUtils.isEmpty(param.getStoreName())){
				msg+="终端代码和终端名称必须输入一个值;\n";
			}
		}else{
			msg="传入参数不能为空;";
		}
		return msg;
	}
	
}
